﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.ComponentModel;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using TA.Turbo.Controls;

namespace TA.Turbo
{
	/// <summary>
	/// Template which is only instantiated and rendered once.
	/// </summary>
	[ParseChildren(true, "Template")]
	//[PersistChildren(false)]
	public class SingleInstanceTemplate : MarkupTemplate
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		/// <param name="name"></param>
		public SingleInstanceTemplate(string name)
			: base(name, TemplateInstance.Single)
		{
		}
		#endregion
		#region PROPS
		/// <summary>
		/// The template.
		/// </summary>
		[PersistenceMode(PersistenceMode.InnerDefaultProperty),
		MergableProperty(false),
		Browsable(false),
		TemplateInstance(TemplateInstance.Single)
			//, DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
		]
		public ITemplate Template { get { return _template; } set { _template = value; } }
		#endregion
		#region METHODS
		/// <summary>
		/// Initializes this template by adding the proper include and instantiating the ITemplate in the container.
		/// </summary>
		public override void Init()
		{
			base.Init();

			if (this.Container.Parent != null)
			{
				this.Container.ID = this.Container.Parent.ID + TControl.ClientIdSeparator + this.Name;
			}
		}
		#endregion
		#endregion
		#region INTERNAL
		#region METHODS
		protected override BaseTemplateContainer CreateContainer()
		{
			return new ContainerControl();
		}
		#endregion
		#endregion
		#region DECLARATIONS
		class ContainerControl : BaseTemplateContainer
		{
			public override void DoRender(HtmlTextWriter writer)
			{
				base.RenderControl(writer);
			}
		}
		#endregion
	}
}